﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace tsgl
{
    public partial class bibliothecaInfoManage : Form
    {
        public bibliothecaInfoManage()
        {
            InitializeComponent();
        }

        private void bibliothecaInfoManage_Load(object sender, EventArgs e)
        {
            DataTable dt = bibliothecaClass.getBibliothecaDataAll();
            this.dataGridView1.DataSource = dt.DefaultView;
            this.dataGridView1.Columns[8].Width = 120;
            this.dataGridView1.Columns[12].Width = 160;
            this.label3.DataBindings.Clear();
            this.label3.DataBindings.Add("text",dt.DefaultView,"书目编号");
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            bibliothecaInfoAdd bibilothecaInfoAdd = new bibliothecaInfoAdd();
            bibilothecaInfoAdd.ShowDialog();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            this.label3.Visible = true;
            bibliothecaInfoEdit bibliothecaInfoEdit = new bibliothecaInfoEdit(this.label3.Text);
            this.label3.Visible = false;
            bibliothecaInfoEdit.ShowDialog();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要删除此条记录吗？", "警告信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                if (bookDbClass.deleteByDt(this.dataGridView1.CurrentCell.RowIndex, "select * from 书目信息") == true)
                {
                    this.dataGridView1.DataSource = bibliothecaClass.getBibliothecaDataAll();
                    MessageBox.Show("成功删除一条记录！", "提示信息");
                }
                else
                {
                    MessageBox.Show("删除失败,请重试！","提示信息");
                }
            }
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            DataTable dt = bibliothecaClass.getBibliothecaDataAll();
            this.dataGridView1.DataSource = dt;
            this.label3.DataBindings.Clear();
            this.label3.DataBindings.Add("text", dt, "书目编号");
            //this.txtBibliothecaId.Text = "";
            //this.txtBiblithecaName.Text = "";
        }

        private void btnSelectAll_Click(object sender, EventArgs e)
        {
            DataTable dt = bibliothecaClass.getBibliothecaDataAll();
            this.dataGridView1.DataSource = dt;
            this.label3.DataBindings.Clear();
            this.label3.DataBindings.Add("text", dt, "书目编号");
            this.txtBibliothecaId.Text = "";
            this.txtBiblithecaName.Text = "";
        }

        private void txtBiblithecaName_TextChanged(object sender, EventArgs e)
        {
            DataTable dt = queryLoanClass.getBibliothecaInfoByName(this.txtBiblithecaName.Text.Trim());
            this.dataGridView1.DataSource = dt.DefaultView;
            this.dataGridView1.Columns[8].Width = 120;
            this.dataGridView1.Columns[12].Width = 160;
            this.label3.DataBindings.Clear();
            this.label3.DataBindings.Add("text", dt.DefaultView, "书目编号");
        }

        private void txtBibliothecaId_TextChanged(object sender, EventArgs e)
        {
            DataTable dt = queryLoanClass.getBibliothecaInfoById(this.txtBibliothecaId.Text.Trim());
            this.dataGridView1.DataSource = dt.DefaultView;
            this.dataGridView1.Columns[8].Width = 120;
            this.dataGridView1.Columns[12].Width = 160;
            this.label3.DataBindings.Clear();
            this.label3.DataBindings.Add("text", dt.DefaultView, "书目编号");
        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            if (this.dataGridView1.Rows.Count != 0)
            {
                for (int i = 0; i < this.dataGridView1.Rows.Count; )
                {
                    this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;
                    i += 2;
                }
            } 

        }
    }
}